package com.example.aicodehelper.AI;


import dev.langchain4j.data.message.AiMessage;
import dev.langchain4j.data.message.SystemMessage;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.chat.response.ChatResponse;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class AiCodeHelper {

    private final static Logger logger = LoggerFactory.getLogger(AiCodeHelper.class);

    @Resource
    private ChatModel qwenChatModel;

    private static final String SYSTEM_MESSAGE = """
            你是编程领域的小助手，帮助用户解答编程学习和面试相关的问题，并给出建议，重点关注4个方向：
            1、规划清晰的编程学习路线
            2、提供项目学习建议
            3、给出程序员求职全流程指南（比如简历优化、投递技巧）
            4、分享高频面试题和面试技巧
            使用简单易懂的语言回答，助力用户高效学习和求职
            """;

    public String chat(String message) {
        SystemMessage systemMessage = SystemMessage.from(SYSTEM_MESSAGE);
        UserMessage userMessage = UserMessage.from(message);
        ChatResponse chatResponse = qwenChatModel.chat(systemMessage, userMessage);
        AiMessage aiMessage = chatResponse.aiMessage();
        logger.info("AI输出：{}", aiMessage.toString());
        return aiMessage.text();
    }

}
